<?php
/**
 * LK controller控制器基类
 * @ category   LK
 * @ package  LK
 * @ subpackage  core
 * @ yangzg <yangzhiguo0903@163.com>
 * @ version  $Id$
 */
defined('IN_LK') or die('Access Denied');
class controller
{
	public function __construct()
	{
		$param = lk::lo('param');
		$params = $param->get_param();
		define('M', $params['m']);
		define('C', $params['c']);
		define('A', $params['a']);
		$this->initialize();
	}
	
   /**
    * 调用控制器类中的方法
	* 禁止调用私有属性
    */
	private function initialize()
	{
		$controller = $this->load_controller();
		if(method_exists($controller, A) && is_callable(array($controller, A)))
		{
			call_user_func(array($controller, A));
		}
		else
		{
			exit(sprintf(LANG('undefined_action'), A));
		}
	}
	
   /**
    * 调用控制器
	*/
	private function load_controller()
	{
		$classname = C;
		$path = CONTROLLERS_PATH . M . DIRECTORY_SEPARATOR . $classname . '.class.php';
		if(is_file($path))
		{
			include $path;
			return new $classname;
		}
		else
		{
			exit(sprintf(LANG('undefined_controller'), $classname));
		}
	}
}